home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13358 < prev    next >
Encoding:
Text File  |  1996-08-05  |  6.8 KB  |  249 lines

  1. Path: news.itsnet.com!usenet
  2. From: Jonathan Ord <jord@itsnet.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: PLEASE HELP ME FINISH A TUTORIAL I AM STUCK.  THANKS
  5. Date: Sun, 24 Mar 1996 20:23:37 -0800
  6. Organization: Internet Technology Systems, Provo UT USA
  7. Message-ID: <31561FC9.77DA@itsnet.com>
  8. NNTP-Posting-Host: ip211.itsnet.com
  9. Mime-Version: 1.0
  10. Content-Type: multipart/mixed; boundary="------------29E172193294"
  11. X-Mailer: Mozilla 2.0 (Win95; I)
  12.  
  13. This is a multi-part message in MIME format.
  14.  
  15. --------------29E172193294
  16. Content-Type: text/plain; charset=us-ascii
  17. Content-Transfer-Encoding: 7bit
  18.  
  19. I am just starting out and having some trouble.  I am trying to learn 
  20. this out of a book.  I have started by trying to complete an assignment 
  21. using linked lists and functions.  I continue to get errors and can't 
  22. figure out how to delete a record from a specified record in the lists 
  23. that I create.
  24.  
  25. This is the criteria for the excercise.  
  26.  
  27. Your program must display the following menu:
  28. 1.    Add a stamp to the list
  29. 2.    Display all the stamps in your list
  30. 3.    Display the least expensive stamp in the list
  31. 4.    Display the most expensive stamp in the list
  32. 5.    Remove a particular stamp from the list
  33. 6.    Exit the program
  34.  
  35. After displaying the menu, ask the user to enter a choice, then perform 
  36. the requested action and repeat this process until the user chooses to 
  37. exit.
  38. Design an appropriate sturcture to capture 3 properties of stamp 
  39. collection.  Store the stamps in a linked list. (using C++ new and 
  40. delete operators to allocate and deallocate storage for the stamp 
  41. structures.
  42. Be sure that all of the structures work whether the list is empty or 
  43. not.  Redisplay the menu if a choice is not valid.
  44. For item 5, I have to devise a way for the user to indicate which stamp 
  45. is to be deleted.  Two possibilities include asking the user for a 
  46. description of the stam to delete or showing the user each stamp and 
  47. asking him or her to say whether this is the one to delete.
  48.  
  49. Anyone that can help me please feel free to look at my program and make 
  50. changes and comments and e-mail it back to me @jord@itsnet.com .
  51.  
  52. I would like to receive some feedback tonight if possible.  Thank you in 
  53. advance for the help.
  54. --
  55.  
  56. --------------29E172193294
  57. Content-Type: text/plain; charset=us-ascii
  58. Content-Transfer-Encoding: 7bit
  59. Content-Disposition: inline; filename="Exam_2.cpp"
  60.  
  61. /*    Jonathan Ord
  62.     ISYS 440 Exam #2
  63.     Dr. Little
  64.     March 23, 1996
  65.     Description ==The program will let me keep track of rare stamps through the
  66.     use of the functions associated with the following menu:
  67.         1.  Add stamp to list
  68.         2.     Display all the stamps in the list
  69.         3.     Display the least expensive stamp in the list
  70.         4.  Display the most expensive stamp in the list
  71.         5.  Remove a particular stamp from the list
  72.         6.     Exit the program
  73. */
  74. //------------------------------------------------------------------------------
  75. //INCLUDES
  76.  
  77. #include <iostream.h>
  78. #include <string.h>
  79.  
  80. //------------------------------------------------------------------------------
  81. //VARIABLES
  82.  
  83. struct STAMP {
  84.     char    *name;
  85.     long    price;
  86.     int    mint_number;
  87.     STAMP    *next;
  88. };
  89.  
  90. const int MAX_STRING_LEN = 128;
  91.  
  92. //==============================================================================
  93. //FUNCTIONS
  94. //------------------------------------------------------------------------------
  95. //Enter stamp data function
  96.  
  97. void
  98. Enter_Stamp_Data(STAMP *stp)
  99. {
  100.     char    temp_string[MAX_STRING_LEN];
  101.  
  102.     cout    <<    "ENTER THE STAMP NAME: ";
  103.     cin.get(temp_string, MAX_STRING_LEN);
  104.     stp->name = new char [strlen(temp_string) + 1];
  105.     strcpy(stp->name, temp_string);
  106.     cout    << "ENTER THE STAMP'S PRICE IN PESETAS: ";
  107.     cin    >>    stp->price;
  108.     cout  << "ENTER THE STAMP'S MINT NUMBER: ";
  109.     cin    >>    stp->mint_number;
  110. }
  111.  
  112. //------------------------------------------------------------------------------
  113. //Append stamp to end of linked list or end of previous node function
  114.  
  115. void
  116. Append_Stamp_Node(STAMP * &first, STAMP *stp_ptr)
  117. {
  118.     if    (first == NULL)
  119.         first = stp_ptr;
  120.     else {
  121.         STAMP    *current = first;
  122.  
  123.         while (current->next != NULL)
  124.             current = current->next;
  125.         current->next = stp_ptr;
  126.         }
  127. }
  128.  
  129. //------------------------------------------------------------------------------
  130. //Display all of the stamps in the list function
  131.  
  132. void
  133. Display_Stamp_Data(STAMP * &head, STAMP *stp_ptr)
  134. {
  135. for (stp_ptr = head; stp_ptr != NULL; stp_ptr = stp_ptr->next)
  136.     cout << stp_ptr->name << endl;
  137.     cout << stp_ptr->price << endl;
  138.     cout << stp_ptr->mint_number << endl;
  139.     cout << endl;
  140. }
  141.  
  142. //------------------------------------------------------------------------------
  143. //Find most expensive stamp in list function
  144.  
  145. void
  146. Find_Highest_Stamp(STAMP * &head, STAMP *stp_ptr)
  147. {
  148. long     highest_price = 0;
  149. char  name;
  150.  
  151. for (stp_ptr = head; stp_ptr != NULL; stp_ptr = stp_ptr->next) {
  152.     if    (stp_ptr->price > highest_price) {
  153.         highest_price = stp_ptr->price;
  154.         name = stp_ptr->name;
  155.         }
  156.     }
  157. cout    << "THE MOST EXPENSIVE STAMP IN THE LIST IS: " << name    <<    endl;
  158. cout    << "THE COST OF " <<    name <<    "IS "    <<    highest_price    <<    endl;
  159. }
  160. //------------------------------------------------------------------------------
  161. //Find least expensive stamp in list function
  162.  
  163. void
  164. Find_Lowest_Stamp(STAMP * &head, STAMP *stp_ptr)
  165. {
  166. long     lowest_price = 2,147,483,647;
  167. char  name;
  168.  
  169. for (stp_ptr = head; stp_ptr != NULL; stp_ptr = stp_ptr->next) {
  170.     if    (stp_ptr->price < lowest_price) {
  171.         lowest_price = stp_ptr->price;
  172.         name = stp_ptr->name;
  173.         }
  174.     }
  175. cout    << "THE LEAST EXPENSIVE STAMP IN THE LIST IS: " << name    <<    endl;
  176. cout    << "THE COST OF " <<    name <<    "IS "    <<    lowest_price    <<    endl;
  177. }
  178. //------------------------------------------------------------------------------
  179. //Delete a choosen record from the list function
  180.  
  181. void
  182. Delete_Stamp_Data(STAMP * &head, STAMP *stp_ptr)
  183. {
  184. int answer;
  185.  
  186. for (stp_ptr = head; stp_ptr != NULL; stp_ptr = stp_ptr->next)
  187.     cout << stp_ptr->name << endl;
  188.     cout << stp_ptr->price << endl;
  189.     cout << stp_ptr->mint_number << endl;
  190.     cout << endl;
  191.     cout << "DO YOU WANT TO DELETE THIS RECORD? (Y FOR YES, N FOR NO) " << endl;
  192.     cin  >> answer >> endl;
  193.         if (answer == 'y') {
  194.                      }}
  195.  
  196. //==============================================================================
  197. //Main Program - references above functions to accomplish stamp assignment
  198.  
  199. void
  200. main()
  201. {
  202. STAMP    *head = NULL,
  203.         *stp_ptr;
  204. int    answer;
  205.  
  206. cout     <<    "CHOOSE ONE (1-6) OF THE FOLLOWING MENU OPTIONS:"    <<    endl;
  207. cout  <<    "1    --    ADD A NEW STAMP RECORD"    <<    endl;
  208. cout    <<    "2    --    DISPLAY ALL THE STAMPS IN THE LIST"    <<    endl;
  209. cout    <<    "3    --    DISPLAY THE MOST EXPENSIVE STAMP IN THE LIST"  << endl;
  210. cout  << "4 -- DISPLAY THE LEAST EXPENSIVE STAMP IN THE LIST"  << endl;
  211. cout    <<    "5 -- REMOVE A STAMP FROM THE LIST"    <<    endl;
  212. cout    << "6    --    EXIT THIS PROGRAM"    << endl;
  213.  
  214. cin    >>    answer    >>    endl;
  215.  
  216. switch(answer)
  217. {
  218. case 1:
  219.     stp_ptr = new STAMP;
  220.     stp_ptr->next = NULL;
  221.     Enter_Stamp_Data(stp_ptr);
  222.     Append_Stamp_Node(head, stp_ptr;
  223.     break;
  224. case 2:
  225.  
  226.     break;
  227. case 3:
  228.  
  229.     break;
  230. case 4:
  231.  
  232.     break;
  233. case 5:
  234.  
  235.     break;
  236. case 6:
  237.  
  238.     break;
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245. }
  246.  
  247. --------------29E172193294--
  248.  
  249.